﻿using System;
using System.Collections.Generic;
using System.IO;

namespace GJXQGame
{
    public partial class Act1Base : IDataBase<ushort>
    {
        public ushort ID;		//所属关卡
        public string PartMyData;		//当前关卡我方的棋盘格数据
        public string PartOtherData;		//当前关卡对方方的棋盘格数据
        public List<DateModelControl.ChessDate> MyChessData = new List<DateModelControl.ChessDate>();
        public List<DateModelControl.ChessDate> OtherChessData = new List<DateModelControl.ChessDate>();
        public string namekey;

        public Act1Base() { }
        //public uint getKeyValue() { return 0; }
        public ushort GetID() { return ID; }

        public bool ParseData(BinaryReader reader)
        {
            try
            {
                ID = reader.ReadUInt16();
                {
                    byte[] buf = reader.ReadBytes(reader.ReadUInt16());
                    PartMyData = TableManager.Bytes2String(buf);
                    string[] arrbuf;
                    arrbuf = PartMyData.Split('|');
                    for (byte n = 0; n < arrbuf.Length; ++n)
                    {
                        string[] arrbuf2 = arrbuf[n].Split(',');
                        if (arrbuf2.Length != 3)
                        {
                            UnityEngine.Debug.Log(string.Format("FormationTable ID:{0} error", ID));
                            return false;
                        }
                        DateModelControl.ChessDate itemDetail;
                        itemDetail.point.Point_x = Convert.ToInt32(arrbuf2[0]);
                        itemDetail.point.Point_y = Convert.ToInt32(arrbuf2[1]);
                        itemDetail.datetype.power = Convert.ToInt32(arrbuf2[2]);
                        itemDetail.datetype.type = TypePlay.My;
                        MyChessData.Add(itemDetail);
                    }
                }
                {
                    byte[] buf = reader.ReadBytes(reader.ReadUInt16());
                    PartOtherData = TableManager.Bytes2String(buf);
                    string[] arrbuf;
                    arrbuf = PartOtherData.Split('|');
                    for (byte n = 0; n < arrbuf.Length; ++n)
                    {
                        string[] arrbuf2 = arrbuf[n].Split(',');
                        if (arrbuf2.Length != 3)
                        {
                            UnityEngine.Debug.Log(string.Format("FormationTable ID:{0} error", ID));
                            return false;
                        }
                        DateModelControl.ChessDate itemDetail;
                        itemDetail.point.Point_x = Convert.ToInt32(arrbuf2[0]);
                        itemDetail.point.Point_y = Convert.ToInt32(arrbuf2[1]);
                        itemDetail.datetype.power = Convert.ToInt32(arrbuf2[2]);
                        itemDetail.datetype.type = TypePlay.Other;
                        MyChessData.Add(itemDetail);
                    }
                }
                {
                    byte[] buf = reader.ReadBytes(reader.ReadUInt16());
                    namekey = TableManager.Bytes2String(buf);
                }
            }
            catch
            {
                return false;
            }
            return true;
        }



    }
}
